package com.asman.vr.utils

/**
 * @author ybk
 * @date :2020-01-18 15:48
 * @desc:
 */

object OSSFullUrlUtils {


    /**
     * /获得公有oss文件地址
     * @param bucketName asman-img
     * @param endpoint  http://oss-cn-hangzhou.aliyuncs.com   https://oss-cn-hangzhou.aliyuncs.com
     * @param name 4d4bdcfd-df71-4fe8-9983-d2f54981bd01.mp3
     * @return https://asman-img.oss-cn-hangzhou.aliyuncs.com/4d4bdcfd-df71-4fe8-9983-d2f54981bd01.mp3
     */
    fun getPublicFullUrl(bucketName: String, endpoint: String, name: String): String {
        return when {
            endpoint.contains("http://") -> {
                val endpoint1 = endpoint.replace("http://", "")
                "https://${bucketName}.$endpoint1/$name"
            }
            endpoint.contains("https://") -> {
                val endpoint1 = endpoint.replace("https://", "")
                "https://${bucketName}.$endpoint1/$name"
            }
            else -> {
                ""
            }
        }
    }
}